package zhangmengna.controller;

import zhangmengna.entity.Page;
import zhangmengna.entity.PageUtils;
import zhangmengna.entity.ZMNBJEntity;
import zhangmengna.entity.ZMNEntity;
import zhangmengna.service.ZMNService;

import javax.annotation.Resource;
import java.util.List;

public class ZMNController {
    Page page=null;
    List<ZMNBJEntity> clazzEntity=null;
    ZMNEntity zmnEntity=null;
    String name=null;
    Integer pageNo=null;
    String flag="0";
    //@Resource @Autowired 作用相同 去spring容器中到bean实例
    //@Service @Component 向spring 容器中放入bean（类的对象）实例
    @Resource
    ZMNService zmnService;
    //分页查看
    public String queryPage(){
        //总条数
        int totalCount=zmnService.queryCount(name);
        //实现一个分页查询功能，计算
        page=PageUtils.getPage(5,totalCount,pageNo);
       List<ZMNEntity> list=zmnService.queryPage(page,name);
       page.setData(list);
       System.out.println(list);
        System.out.println("11111111111111");
       System.out.println(page);
        return "queryPage";
    }
    //添加
    public String add(){
        zmnService.add(zmnEntity);
        flag="1";
        return "add";
    }
    //修改
   public String edit(){
        zmnEntity=zmnService.edit(zmnEntity);
        System.out.println("修改！");
        return "edit";
    }
    //删除
    public String del(){
        System.out.println(zmnEntity);
        zmnService.del(zmnEntity);
        flag="1";
        //System.out.println(list);
        return "del";//-->result 标签的name属性
    }
    //
  public String clazz(){
        clazzEntity=zmnService.clazz();
      System.out.println("班级");
        return "clazz";
    }


    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }

    public List<ZMNBJEntity> getClazzEntity() {
        return clazzEntity;
    }

    public void setClazzEntity(List<ZMNBJEntity> clazzEntity) {
        this.clazzEntity = clazzEntity;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public ZMNEntity getZmnEntity() {
        return zmnEntity;
    }

    public void setZmnEntity(ZMNEntity zmnEntity) {
        this.zmnEntity = zmnEntity;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }
}
